package com.zoe.app.entity;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author Zoe.Zhang
 * @date 2021/09/23
 * @description
 */
@Component(value = "${user.user-name}")
public class User {
    // ${} 从配置文件中取值
    // #{} 从容器中取bean进行注入,也可以进行逻辑运算

    // 常量赋值
    @Value("black")
    private String Color;

    // 从配置文件中取值
    @Value("${user.user-name}")
    private String userName;

    // 从容器根据beanName拿到 mycar 这个bean注入到这里,如果找不到bean则会报异常
    @Value("#{mycar}")
    private Car car;

    // 从容器根据beanName拿到 mycar的name属性 注入到这里,如果找不到bean则会报异常
    @Value("#{mycar.name}")
    private String carName;

    // 逻辑运算
    @Value("#{1+1}")
    private Integer age;

    @Value("${user.weight}")
    private String weight;

    @Value("${user.height}")
    private String height;

    private static String like;

    // @value 不能直接给静态变量赋值,所以要通过set方法来赋值,注意set方法不能是静态的
    @Value("${user.like}")
    public void setLike(String like) {
        System.out.println("setLike==>" + like);
        User.like = like;
    }

    public String getLike() {
        return like;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        System.out.println("setUserName===>" + userName);
        this.userName = userName;
    }

    public Car getCar() {
        return car;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    public String getCarName() {
        return carName;
    }

    public void setCarName(String carName) {
        this.carName = carName;
    }

    public String getColor() {
        return Color;
    }

    public void setColor(String color) {
        Color = color;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
    }

    public String getHeight() {
        return height;
    }

    public void setHeight(String height) {
        this.height = height;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + userName + '\'' +
                ", car=" + car +
                ", carName='" + carName + '\'' +
                ", Color='" + Color + '\'' +
                ", age=" + age +
                ", weight='" + weight + '\'' +
                ", height='" + height + '\'' +
                ", like=" + User.like +
                '}';
    }
}
